﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Orchard.ContentManagement;
using Orchard.Data;
using Orchard.Commerce.Models;
using Orchard.UI.Admin;
namespace Orchard.Commerce.Controllers
{
   
    public class CategoryController : Controller
    {
        private readonly IContentManager _contentManager;

        public CategoryController(IContentManager contentManager) {
            _contentManager = contentManager;
        }


        public ActionResult Index()
        {
            return View(_contentManager.Query<Category>().List());
        }

        public ActionResult Create()
        {
            return View(_contentManager.New<Category>("category"));
        }

        [HttpPost]
        public ActionResult Create(FormCollection input)
        {
            var category = _contentManager.New<Category>("category");

            if (!TryUpdateModel(category))
            {
                return View(category);
            }

            _contentManager.Create(category);

            return RedirectToAction("Index");
        }


    }
}
